package com.csii.modules.message.handle.impl;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.csii.modules.message.handle.ISendMsgHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class DingTalkSendMsgHandle implements ISendMsgHandle {

	@Override
	public void SendMsg(String es_receiver, String es_title, String es_content) {
		RestTemplate restTemplate=new RestTemplate();
		JSONObject jsonObject=new JSONObject();
		//{"msgtype": "text","text": {"content": "我就是我, 是不一样的烟火"}}
		jsonObject.put("msgtype","text");
		Map<String,String> msg=new HashMap();
		msg.put("content", (StrUtil.isEmpty(es_receiver)?"":("@"+es_receiver+"\n"))+es_title+"\n"+es_content);
		jsonObject.put("text",msg);
		String res=restTemplate.postForObject("https://oapi.dingtalk.com/robot/send?access_token=9648260e3e7fc163191a2c1f9dca83dad95047fc5ef9e88c7d5deb18da7a570d",jsonObject,String.class);
		log.info(jsonObject.toJSONString()+"===>>>>"+res);
	}

}
